import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

// SpringMvc只扫描Controller子容器
// useDefaultFilters=false 禁用默认的过滤规则
@ComponentScan(value = "/",includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})},useDefaultFilters = false)
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {

    // 定制

    // 视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // return this.jsp("/WEB-INF/", ".jsp");默认从....中找
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截任务多的请求
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
    }
}
